
module Cms
  class Window < Fragment

    state_defined_by :name => 'New page', :uuid => nil

    def get_icon
      icon = Browser::Icon.new
      icon.label = name
      icon.uuid = self.uuid
      icon
    end

    def header
      e :div, :class => 'head' do
        add hf = InputFragment.new(:class => 'pageTitle')
        hf.data = name
        hf.draggable = false
        e :div, :class => 'windowButtons' do
          add UI::Button.new(:class => 'deleteWindow', :innerHTML => "delete")
          add UI::Button.new(:class => 'saveWindow', :innerHTML => "save")
          add UI::Button.new(:class => 'closeWindow', :innerHTML => "close")
        end
      end
    end

    def build
      container = el :div, :class => 'pageContainer', :id => generate_id

      container.children = self.children
      self.children = []

       e :script, "
        dcat_instance.oninit(function() {
          new Cat.Page(document.getElementById('#{id}'), #{options});
        });
      "      
      
      header
      
      add container
    end
  end
end
